<?php
/**
 *导出
 */
namespace App\Http\Controllers\Excel;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\FromCollection;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Style\Alignment;
use PhpOffice\PhpSpreadsheet\Style\Border;



class CheckExport implements FromCollection,WithStyles
{ 
    private $data;

    public function __construct($data)
    {
        $this->data = $data;     
    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        return collect($this->data);
    }

    public function styles(Worksheet $sheet){

        // 合并单元格
        $sheet->mergeCells('A1:I1');
        $sheet->mergeCells('A2:I2');
        $sheet->mergeCells('A3:B3');
        //$sheet->mergeCells('C3:E3');
        //$sheet->mergeCells('F3:I3');
        $sheet->mergeCells('A3:D3');
        $sheet->mergeCells('E3:I3');
        $sheet->mergeCells('A4:D4');
        $sheet->mergeCells('E4:I4');
       
        // $sheet->mergeCells('D13:E13');
        // $sheet->mergeCells('D14:E14');
        // $sheet->mergeCells('D15:E15');
        // $sheet->mergeCells('D16:E16');
        $sheet->mergeCells('D14:E14');
        $sheet->mergeCells('D15:E15');
        $sheet->mergeCells('D16:E16');
        $sheet->mergeCells('D17:E17');

        //  $sheet->mergeCells('D17:I17');
        //  $sheet->mergeCells('D18:I18');
        //  $sheet->mergeCells('D19:I19');
         $sheet->mergeCells('D18:I18');
         $sheet->mergeCells('D19:I19');
         $sheet->mergeCells('D20:I20');

        //$sheet->mergeCells('D20:I23');
        $sheet->mergeCells('D21:I24');
        // $sheet->mergeCells('F24:I24');
        // $sheet->mergeCells('C24:E24');
        // $sheet->mergeCells('A24:B24');
        $sheet->mergeCells('F25:I25');
        $sheet->mergeCells('C25:E25');
        $sheet->mergeCells('A25:B25');
 
        //$sheet->mergeCells('D17:I17');
        //$sheet->mergeCells('A3:I3');
     
        // 设置列宽
        $sheet->getColumnDimension('A')->setWidth(4);
        $sheet->getColumnDimension('B')->setWidth(23);
        $sheet->getColumnDimension('C')->setWidth(6);
        $sheet->getColumnDimension('D')->setWidth(4);
        $sheet->getColumnDimension('E')->setWidth(22);
        $sheet->getColumnDimension('F')->setWidth(6);
        $sheet->getColumnDimension('G')->setWidth(5);
        $sheet->getColumnDimension('H')->setWidth(8);
        $sheet->getColumnDimension('I')->setWidth(9);

        // 设置默认行高
        //$sheet->getDefaultRowDimension()->setRowHeight(28);
        //设置行高
        $sheet->getRowDimension('1')->setRowHeight(28);
        $sheet->getRowDimension('2')->setRowHeight(28);
        $sheet->getRowDimension('3')->setRowHeight(28);
        $sheet->getRowDimension('4')->setRowHeight(28);
        $sheet->getRowDimension('5')->setRowHeight(28);
        $sheet->getRowDimension('6')->setRowHeight(28);
        $sheet->getRowDimension('7')->setRowHeight(28);
        $sheet->getRowDimension('8')->setRowHeight(28);
        $sheet->getRowDimension('9')->setRowHeight(28);
        $sheet->getRowDimension('10')->setRowHeight(28);
        $sheet->getRowDimension('11')->setRowHeight(28);
        $sheet->getRowDimension('12')->setRowHeight(28);
        $sheet->getRowDimension('13')->setRowHeight(28);
        $sheet->getRowDimension('14')->setRowHeight(28);
        $sheet->getRowDimension('15')->setRowHeight(28);
        $sheet->getRowDimension('16')->setRowHeight(28);
        $sheet->getRowDimension('17')->setRowHeight(28);
        $sheet->getRowDimension('18')->setRowHeight(28);
        $sheet->getRowDimension('19')->setRowHeight(28);
        $sheet->getRowDimension('20')->setRowHeight(28);
        $sheet->getRowDimension('21')->setRowHeight(28);
        $sheet->getRowDimension('22')->setRowHeight(28);
        $sheet->getRowDimension('23')->setRowHeight(28);
        $sheet->getRowDimension('24')->setRowHeight(28);
        $sheet->getRowDimension('25')->setRowHeight(28);

        //$sheet->getStyle('D20:I23')->getAlignment()->setWrapText(true);
        $sheet->getStyle('D21:I24')->getAlignment()->setWrapText(true);

        //垂直水平居中
        $sheet->getStyle('A1')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);     
        //$sheet->getStyle('A4:A23')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('A5:A24')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
        //$sheet->getStyle('C4:C23')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('C5:C24')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
        //$sheet->getStyle('D4:D12')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('D5:D13')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
        //$sheet->getStyle('F4:I16')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('F5:I17')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
        // $sheet->getStyle('B4')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
        // $sheet->getStyle('E4')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('B5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('E5')->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER)->setVertical(Alignment::VERTICAL_CENTER);
        //$sheet->getStyle('B5:B23')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('B6:B24')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        //$sheet->getStyle('E5:E12')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('E6:E13')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('A2:I2')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('A3:I4')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        //$sheet->getStyle('A24:I24')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('A25:I25')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        //$sheet->getStyle('A20:I23')->getAlignment()->setVertical(Alignment::VERTICAL_TOP);
        $sheet->getStyle('A21:I24')->getAlignment()->setVertical(Alignment::VERTICAL_TOP);
        //$sheet->getStyle('D17:I19')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('D18:I20')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        //$sheet->getStyle('D13:E16')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('D14:E17')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        //$sheet->getStyle('B20:B23')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('B21:B24')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        //$sheet->getStyle('A16:A23')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('A17:A24')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        //$sheet->getStyle('C20:C23')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);
        $sheet->getStyle('C21:C24')->getAlignment()->setVertical(Alignment::VERTICAL_CENTER);

        //设置边框      
        //$sheet->getStyle('A4:I23')->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN);
        $sheet->getStyle('A5:I17')->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN);
        $sheet->getStyle('A18:C20')->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN);
        $sheet->getStyle('A21:I24')->getBorders()->getAllBorders()->setBorderStyle(Border::BORDER_THIN);
        //$sheet->getStyle('D17:I17')->getBorders()->getBottom()->setBorderStyle(Border::BORDER_DASHDOT);
        $sheet->getStyle('D18:I20')->getBorders()->getRight()->setBorderStyle(Border::BORDER_THIN);

        //设置字体
        $sheet->getStyle('A1')->getFont()->setSize(18)->setBold(true);
    }




    
    
}

?>
